package cn.edu.cqupt.cxcy.dto;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import cn.edu.cqupt.cxcy.dao.IndexDao;
import cn.edu.cqupt.cxcy.model.Admin;
import cn.edu.cqupt.cxcy.model.Field;
import cn.edu.cqupt.cxcy.model.Fieldtype;
import cn.edu.cqupt.cxcy.model.GuiDirection;
import cn.edu.cqupt.cxcy.model.Investor;
import cn.edu.cqupt.cxcy.model.Member;
import cn.edu.cqupt.cxcy.model.Notice;
import cn.edu.cqupt.cxcy.model.Noticetype;
import cn.edu.cqupt.cxcy.model.ProjecType;
import cn.edu.cqupt.cxcy.model.Project;
import cn.edu.cqupt.cxcy.model.Projectinvest;
import cn.edu.cqupt.cxcy.model.Team;
import cn.edu.cqupt.cxcy.model.Teamunite;
import cn.edu.cqupt.cxcy.model.Tutor;
import cn.edu.cqupt.cxcy.util.Conn;

public class IndexImpl implements IndexDao {

	/**
	 * 登录检查(用户名唯一)<br />
	 * 若没有用户,则返回空的集合 用isEmpty()检验
	 */
	@Override
	public List<Object> login(List<Object> list) {
		List<String> sql = new ArrayList<>();
		sql.add("select a_logo as logo,a_name as name,a_id as id,a_loname as loname from admin where a_loname=? and a_passw=?;");
		sql.add("select tu_logo as logo,tu_name as name,tu_id as id,tu_loname as loname  from tutor where tu_loname=? and tu_passw=?;");
		sql.add("select i_logo as logo,i_name as name,i_id as id,i_loname as loname  from investor where i_loname=? and i_passw=?;");
		sql.add("select te_logo as logo,te_name as name,te_id as id,te_loname as loname  from team where te_loname=? and te_passw=?;");
		List<Object> user = new ArrayList<>();
		for(int i=3; i>-1; i--) {
			Connection conn = null;
			PreparedStatement ps = null;
			ResultSet rs = null;
			try {
				conn = Conn.getConnect();
				System.out.println("connected");
				ps = conn.prepareStatement(sql.get(3-i));
				ps.setString(1, (String) list.get(0));
				ps.setString(2, (String) list.get(1));
				rs = ps.executeQuery();
				if(rs != null && rs.next()) {
					rs.first();
					do{
						user.add(rs.getString("name"));
						user.add(rs.getInt("id"));
						user.add(4-i);
						user.add(rs.getString("logo"));
						user.add(rs.getString("loname"));
					}while(rs.next());
					break;
				}
			} catch (SQLException e) {
				e.printStackTrace();
				throw new RuntimeException(e.getMessage());
			} finally {
				Conn.close(rs, ps, conn);
			}
		}
		return user;
	}

	@Override
	public List<Integer> getCountNess() {
		List<Integer> ness = new ArrayList<>();
		List<String> sql = new ArrayList<>();
		sql.add("select count(te_id) as count from team;");
		sql.add("select count(tu_id) as count from tutor;");
		sql.add("select count(i_id) as count from investor;");
		sql.add("select count(p_id) as count from project;");
		sql.add("select sum(pi_amount) as count from projectInvest;");
		for(int i=0; i<5; i++) {
			Connection conn = null;
			PreparedStatement ps = null;
			ResultSet rs = null;
			try {
				conn = Conn.getConnect();
				ps = conn.prepareStatement(sql.get(i));
				rs = ps.executeQuery();
				while(rs.next()) {
					ness.add(rs.getInt("count"));
				}
			} catch (SQLException e) {
				e.printStackTrace();
				throw new RuntimeException(e.getMessage());
			} finally {
				Conn.close(rs, ps, conn);
			}
		}
		int temp = ness.get(4)/10000;	ness.set(4, temp) ;
		return ness;
	}

	@Override
	public List<Object> getNewProList() {
		List<Object> lists = new ArrayList<>();  
		String sql = "select * from project p left join projectInvest pi on p.p_id=pi.p_id left join investor i on i.i_id=pi.i_id left join team te on te.te_id=p.te_id where p.p_progress=0 and p.p_status=2 ORDER BY p.p_ctime desc limit 0,?;";
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		Project pro = null;
		Projectinvest pi = null;
		Investor in = null;
		Team te = null;
		List<Object> list = null;
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(sql);
			ps.setInt(1, IndexDao.INDEX_NEWPRO);
			rs = ps.executeQuery();
			while (rs.next()) {
				pro = new Project();//项目的容器
				pi = new Projectinvest();//项目与投资人关系的容器
				in = new Investor();//投资人的容器
				te = new Team();//团队的容器
				list = new ArrayList<>();//装上面五个的容器
				pro.setP_content(rs.getString("P_content"));
				pro.setP_ctime(rs.getDate("P_ctime"));
				pro.setP_explain(rs.getString("P_explain"));
				pro.setP_id(rs.getInt("P_id"));	
				pro.setTe_id(rs.getInt("p_view"));
				pro.setP_logo(rs.getString("P_logo"));
				pro.setP_ltime(rs.getDate("P_ltime"));
				pro.setP_name(rs.getString("P_name"));
				pro.setP_progress(rs.getInt("P_progress"));
				pro.setP_status(rs.getInt("p_status"));
				pro.setTe_id(rs.getInt("Te_id"));
				pro.setP_zan(rs.getInt("p_zan"));

				pi.setI_id(rs.getInt("I_id"));
				pi.setP_id(rs.getInt("P_id"));
				pi.setPi_amount(rs.getDouble("Pi_amount"));
				pi.setPi_explain(rs.getString("Pi_explain"));
				pi.setPi_id(rs.getInt("Pi_id"));
				pi.setPi_time(rs.getDate("Pi_time"));

				in.setI_explain(rs.getString("I_explain"));
				in.setI_id(rs.getInt("I_id"));
				in.setI_logo(rs.getString("I_logo"));
				in.setI_name(rs.getString("I_name"));

				te.setTe_explain(rs.getString("Te_explain"));
				te.setTe_id(rs.getInt("Te_id"));
				te.setTe_logo(rs.getString("Te_logo"));

				list.add(pro);
				list.add(pi);
				list.add(in);
				list.add(te);

				lists.add(list);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			Conn.close(rs, ps, conn);
		}
		return lists;
	}

	@Override
	public List<Object> getProInfo(int proid) {

		String sql = "select * from project p left join projectInvest pi on p.p_id=pi.p_id left join investor i on i.i_id=pi.i_id left join team te on te.te_id=p.te_id where p.p_id=" + proid + ";";
		List<Object> list = new ArrayList<>();//装下面五个的容器
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		Project pro = null;
		Projectinvest pi = null;
		Investor in = null;
		Team te = null;
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery();
			while (rs.next()) {
				pro = new Project();//项目的容器
				pi = new Projectinvest();//项目与投资人关系的容器
				in = new Investor();//投资人的容器
				te = new Team();//团队的容器

				pro.setP_content(rs.getString("P_content"));
				pro.setP_ctime(rs.getDate("P_ctime"));
				pro.setP_explain(rs.getString("P_explain"));
				pro.setP_id(rs.getInt("P_id"));
				pro.setP_view(rs.getInt("p_view"));
				pro.setP_zan(rs.getInt("p_zan"));
				pro.setP_logo(rs.getString("P_logo"));
				pro.setP_ltime(rs.getDate("P_ltime"));
				pro.setP_name(rs.getString("P_name"));
				pro.setP_progress(rs.getInt("P_progress"));
				pro.setP_status(rs.getInt("p_status"));
				pro.setTe_id(rs.getInt("Te_id"));

				pi.setI_id(rs.getInt("I_id"));
				pi.setP_id(rs.getInt("P_id"));
				pi.setPi_amount(rs.getDouble("Pi_amount"));
				pi.setPi_explain(rs.getString("Pi_explain"));
				pi.setPi_id(rs.getInt("Pi_id"));
				pi.setPi_time(rs.getDate("Pi_time"));

				in.setI_explain(rs.getString("I_explain"));
				in.setI_id(rs.getInt("I_id"));
				in.setI_logo(rs.getString("I_logo"));
				in.setI_name(rs.getString("I_name"));

				te.setTe_explain(rs.getString("Te_explain"));
				te.setTe_id(rs.getInt("Te_id"));
				te.setTe_logo(rs.getString("Te_logo"));
				te.setTe_name(rs.getString("te_name"));


				list.add(pro);
				list.add(pi);
				list.add(in);
				list.add(te);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			Conn.close(rs, null, null);
		}
		return list;
	}

	@Override
	public List<Object> getNewSuccessProList() {
		List<Object> lists = new ArrayList<>();  
		String sql = "select * from project p left join projectInvest pi on p.p_id=pi.p_id left join investor i on i.i_id=pi.i_id left join team te on te.te_id=p.te_id where p.p_progress=10 and p.p_status=2 ORDER BY p.p_ctime desc limit 0,?;";
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		Project pro = null;
		Projectinvest pi = null;
		Investor in = null;
		Team te = null;
		List<Object> list = null;
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(sql);
			ps.setInt(1, IndexDao.INDEX_NEWSUCCPRO);
			rs = ps.executeQuery();
			while (rs.next()) {
				pro = new Project();//项目的容器
				pi = new Projectinvest();//项目与投资人关系的容器
				in = new Investor();//投资人的容器
				te = new Team();//团队的容器
				list = new ArrayList<>();//装上面五个的容器
				pro.setP_content(rs.getString("P_content"));
				pro.setP_ctime(rs.getDate("P_ctime"));
				pro.setP_explain(rs.getString("P_explain"));
				pro.setP_id(rs.getInt("P_id"));	
				pro.setTe_id(rs.getInt("p_view"));
				pro.setP_logo(rs.getString("P_logo"));
				pro.setP_ltime(rs.getDate("P_ltime"));
				pro.setP_name(rs.getString("P_name"));
				pro.setP_progress(rs.getInt("P_progress"));
				pro.setP_status(rs.getInt("p_status"));
				pro.setTe_id(rs.getInt("Te_id"));

				pi.setI_id(rs.getInt("I_id"));
				pi.setP_id(rs.getInt("P_id"));
				pi.setPi_amount(rs.getDouble("Pi_amount"));
				pi.setPi_explain(rs.getString("Pi_explain"));
				pi.setPi_id(rs.getInt("Pi_id"));
				pi.setPi_time(rs.getDate("Pi_time"));

				in.setI_explain(rs.getString("I_explain"));
				in.setI_id(rs.getInt("I_id"));
				in.setI_logo(rs.getString("I_logo"));
				in.setI_name(rs.getString("I_name"));

				te.setTe_explain(rs.getString("Te_explain"));
				te.setTe_id(rs.getInt("Te_id"));
				te.setTe_logo(rs.getString("Te_logo"));

				list.add(pro);
				list.add(pi);
				list.add(in);
				list.add(te);

				lists.add(list);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			Conn.close(rs, ps, conn);
		}
		return lists;
	}


	@Override
	public Notice getNewNoticeHaveImg() {
		String sql = "select * from notice where n_content like '%<img src=%' order by n_ctime desc limit 0,1;";
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		Notice no = new Notice();
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(sql.toString());
			rs = ps.executeQuery();
			while (rs.next()) {
				no.setA_id(rs.getInt("A_id"));
				no.setN_content(rs.getString("N_content"));
				no.setN_id(rs.getInt("N_id"));
				no.setN_ctime(rs.getDate("N_ctime"));
				no.setN_title(rs.getString("N_title"));
				no.setN_view(rs.getInt("N_view"));
				no.setNt_id(rs.getInt("Nt_id"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			Conn.close(rs, ps, conn);
		}
		return no;
	}
	
	@Override
	public List<Object> getNewNoticeList( int id, int ntid) {
		List<Object> lists = new ArrayList<>();  
		String sql = "select * from notice n left join noticeType ny on n.nt_id=ny.nt_id left join admin a on a.a_id=n.a_id where n.nt_id=? and n.n_id <> ? ORDER BY n.n_ctime desc limit 0,?;";
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		Notice no = null;
		Noticetype ny = null;
		Admin ad = null;
		List<Object> list = null;
		Noticetype noticetype = null;
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(sql);
			ps.setInt(1, ntid);
			ps.setInt(2, id);
			ps.setInt(3, IndexDao.INDEX_NEWNEW);
			rs = ps.executeQuery();
			while (rs.next()) {
				no = new Notice();
				ny = new Noticetype();
				ad = new Admin();
				list = new ArrayList<>();//装上面3个的容器

				no.setA_id(rs.getInt("A_id"));
				no.setN_content(rs.getString("N_content"));
				no.setN_id(rs.getInt("N_id"));
				no.setN_ctime(rs.getDate("N_ctime"));
				no.setN_title(rs.getString("N_title"));
				no.setN_view(rs.getInt("N_view"));
				no.setNt_id(rs.getInt("Nt_id"));
				no.setN_from(rs.getString("n_from"));

				ny.setNt_explain(rs.getString("Nt_explain"));
				ny.setNt_name(rs.getString("Nt_name"));

				ad.setA_explain(rs.getString("A_explain"));
				ad.setA_id(rs.getInt("A_id"));
				ad.setA_name(rs.getString("A_name"));
				
				noticetype = new Noticetype(
						rs.getInt("nt_id"),
						rs.getString("nt_name"),
						rs.getString("nt_explain"));
				list.add(no);
				list.add(ny);
				list.add(ad);
				list.add(noticetype);

				lists.add(list);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			Conn.close(rs, ps, conn);
		}
		return lists;
	}


	
	@Override
	public List<Object> getNewNoticeList() {
		List<Object> lists = new ArrayList<>();  
		String sql = "select * from notice n left join noticeType ny on n.nt_id=ny.nt_id left join admin a on a.a_id=n.a_id ORDER BY n.n_ctime desc limit 0,4;";
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		Notice no = null;
		Noticetype ny = null;
		Admin ad = null;
		List<Object> list = null;
		Noticetype noticetype = null;
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery();
			while (rs.next()) {
				no = new Notice();
				ny = new Noticetype();
				ad = new Admin();
				list = new ArrayList<>();//装上面3个的容器

				no.setA_id(rs.getInt("A_id"));
				no.setN_content(rs.getString("N_content"));
				no.setN_id(rs.getInt("N_id"));
				no.setN_ctime(rs.getDate("N_ctime"));
				no.setN_title(rs.getString("N_title"));
				no.setN_view(rs.getInt("N_view"));
				no.setNt_id(rs.getInt("Nt_id"));

				ny.setNt_explain(rs.getString("Nt_explain"));
				ny.setNt_name(rs.getString("Nt_name"));

				ad.setA_explain(rs.getString("A_explain"));
				ad.setA_id(rs.getInt("A_id"));
				ad.setA_name(rs.getString("A_name"));
				
				noticetype = new Noticetype(
						rs.getInt("nt_id"),
						rs.getString("nt_name"),
						rs.getString("nt_explain"));
				list.add(no);
				list.add(ny);
				list.add(ad);
				list.add(noticetype);

				lists.add(list);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			Conn.close(rs, ps, conn);
		}
		return lists;
	}
	
	@Override
	public List<Object> getNoticeInfo(int nid) {
		List<Object> lists = new ArrayList<>();  
		String sql = "select * from notice n left join noticeType ny on n.nt_id=ny.nt_id left join admin a on a.a_id=n.a_id where n.n_id=" + nid + ";";
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		Notice no = null;
		Noticetype ny = null;
		Admin ad = null;
		Noticetype noticetype = null;
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery();
			while (rs.next()) {
				no = new Notice();
				ny = new Noticetype();
				ad = new Admin();

				no.setA_id(rs.getInt("A_id"));
				no.setN_content(rs.getString("N_content"));
				no.setN_id(rs.getInt("N_id"));
				no.setN_ctime(rs.getDate("N_ctime"));
				no.setN_title(rs.getString("N_title"));
				no.setN_view(rs.getInt("N_view"));
				no.setNt_id(rs.getInt("Nt_id"));
				no.setN_from(rs.getString("n_from"));

				ny.setNt_explain(rs.getString("Nt_explain"));
				ny.setNt_name(rs.getString("Nt_name"));

				ad.setA_explain(rs.getString("A_explain"));
				ad.setA_id(rs.getInt("A_id"));
				ad.setA_name(rs.getString("A_name"));

				noticetype = new Noticetype(
						rs.getInt("nt_id"),
						rs.getString("nt_name"),
						rs.getString("nt_explain"));
				lists.add(no);
				lists.add(ny);
				lists.add(ad);
				lists.add(noticetype);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			Conn.close(rs, ps, conn);
		}
		return lists;
	}


	@Override
	public void addProView(int proid) {
		String sql = "update project set p_view = p_view+1 where p_id=" + proid + ";";
		Conn.executeUpdate(sql, null);
	}


	@Override
	public void addNewsView(int newsid) {
		String sql = "update notice set n_view=n_view+1 where n_id=" + newsid + ";";
		Conn.executeUpdate(sql, null);
	}

	@Override
	public boolean usernameIsUnique(String username) {
		List<String> sql = new ArrayList<>();
		boolean status = true;
		sql.add("select * from admin where a_loname=?;");
		sql.add("select * from tutor where tu_loname=?;");
		sql.add("select * from investor where i_loname=?;");
		sql.add("select * from team where te_loname=?;");
		for(int i=3; i>-1; i--) {
			Connection conn = null;
			PreparedStatement ps = null;
			ResultSet rs = null;
			try {
				conn = Conn.getConnect();
				ps = conn.prepareStatement(sql.get(3-i));
				ps.setString(1, username);
				rs = ps.executeQuery();
				if(rs != null && rs.next() && rs.getRow()>0) {
					status = false;
					break;
				}
			} catch (SQLException e) {
				e.printStackTrace();
				throw new RuntimeException(e.getMessage());
			} finally {
				Conn.close(rs, ps, conn);
			}
		}
		return status;
	}

	@Override
	public boolean updateCheck( String loname, String check) {
		List<String> sql = new ArrayList<>();
		int ii = 0;
		//sql.add("update admin set a_check=? where a_loname=?;");
		sql.add("update tutor set tu_check=? where tu_loname=?;");
		sql.add("update investor set i_check=? where i_loname=?;");
		sql.add("update team set te_check=? where te_loname=?;");
		for(int i=2; i>-1; i--) {
			Connection conn = null;
			PreparedStatement ps = null;
			try {
				conn = Conn.getConnect();
				ps = conn.prepareStatement(sql.get(2-i));
				ps.setString(1, check);
				ps.setString(2, loname);
				i = ps.executeUpdate();
			} catch (SQLException e) {
				e.printStackTrace();
				throw new RuntimeException(e.getMessage());
			} finally {
				Conn.close(null, ps, conn);
			}
			if(i != 0) {
				break;
			}
		}
		return ii == 0?false:true;
	}


	@Override
	public List<Object> listCdyy(String loname, int page, int count) {
		List<Object> lists = new ArrayList<>();  
		StringBuilder str = new StringBuilder("select * from field f left join fieldType ft on f.ft_id=ft.ft_id where f_user=? ORDER BY f_asktime desc limit ");
		str.append((page-1) * count);
		str.append(",");
		str.append(count);
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		Field field =null;
		Fieldtype fieldtype = null;
		List<Object> list = null;
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(str.toString());
			ps.setString(1, loname);
			rs = ps.executeQuery();
			while (rs.next()) {
				list = new ArrayList<>();  
				field = new Field(
						rs.getInt("f_id"),
						rs.getString("f_peoper"),
						rs.getString("f_tel"),
						rs.getInt("ft_id"),
						rs.getDate("f_asktime"),
						rs.getDate("f_stardate"),
						rs.getString("f_user"),
						rs.getTime("f_startime"),
						rs.getTime("f_endtime"),
						rs.getString("f_explain"),
						rs.getInt("f_status"),
						rs.getString("f_remarks"));
				fieldtype = new Fieldtype(
						rs.getInt("ft_id"),
						rs.getString("ft_name"),
						rs.getString("ft_explain"));
				list.add(field);
				list.add(fieldtype);
				lists.add(list);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			Conn.close(rs, ps, conn);
		}
		return lists;
	}

	@Override
	public List<Team> teamList() {
		List<Team> lists = new ArrayList<>();  
		String sql = "select * from team limit 0,6;";
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		Team team =null;
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery();
			while (rs.next()) {
				team = new Team(
						rs.getString("te_name"),
						rs.getString("te_logo"),
						rs.getString("te_loname"),
						rs.getString("te_passw"),
						rs.getDate("te_ctime"),
						rs.getString("te_explain"),
						rs.getInt("te_id"),
						rs.getString("te_check"));
				lists.add(team);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			Conn.close(rs, ps, conn);
		}
		return lists;
	}

	@Override
	public boolean addCdyy(Field field) {
		StringBuilder sql = new StringBuilder("insert into field ( f_id, f_peoper, f_asktime, f_stardate, f_user, f_startime, f_explain, f_status, f_remarks, ft_id, f_tel, f_endtime) values (0, ?, sysdate(), ?, ?, ?, ?, ?, ?, ?, ?, ?);");
		Connection conn = null;
		PreparedStatement ps = null;
		int flag = 0;
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, field.getF_peoper());
			ps.setDate(2, new java.sql.Date(field.getF_stardate().getTime()));
			ps.setString(3, field.getF_user());
			ps.setTime(4, field.getF_startime());
			ps.setString(5, field.getF_explain());
			ps.setInt(6, 0);
			ps.setString(7, field.getF_remarks());
			ps.setInt(8, field.getFt_id());
			ps.setString(9, field.getF_tel());
			ps.setTime(10, field.getF_endtime());
			flag = ps.executeUpdate();
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			Conn.close( null, ps, conn);
		}
		return flag == 0?false:true;
	}

	@Override
	public List<Object> listTeac(int type, int page, int count) {
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuilder str = new StringBuilder("select * from tutor t left join guiDirection gd on gd.gd_id=t.gd_id ");
		if(type < 3) {
			str.append(" where tu_type=");
			str.append(type);
		}
		str.append(" ORDER BY tu_ctime desc limit ");
		str.append((page-1) * count);
		str.append(",");
		str.append(count);
		List<Object> lists = new ArrayList<>();
		Tutor tutor = null;
		GuiDirection gd = null;
		List<Object> list = null;
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(str.toString());
			rs = ps.executeQuery();
			while(rs.next()) {
				list = new ArrayList<>();
				tutor = new Tutor(
						rs.getInt("tu_id"),
						rs.getString("tu_name"),
						rs.getString("tu_logo"),
						rs.getString("tu_loname"),
						null,
						rs.getString("tu_tel"),
						rs.getString("tu_explain"),
						rs.getDate("tu_ctime"),
						rs.getInt("gd_id"));
				gd = new GuiDirection(
						rs.getInt("gd_id"),
						rs.getString("gd_name"),
						rs.getString("gd_explain"));
				list.add(tutor);
				list.add(gd);
				lists.add(list);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e.getMessage());
		} finally {
			Conn.close(rs, ps, conn);
		}
		return lists;
	}

	@Override
	public int countTeac(int type) {
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuilder str = new StringBuilder("select count(tu_id) as count from tutor ");
		int count = 1;
		if(type < 3) {
			str.append(" where tu_type=");
			str.append(type);
		}
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(str.toString());
			rs = ps.executeQuery();
			while(rs.next()) {
				count = rs.getInt("count");
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e.getMessage());
		} finally {
			Conn.close(rs, ps, conn);
		}
		return count;
	}

	@Override
	public List<Object> listInve(int type, int page, int count) {
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuilder str = new StringBuilder("select * from investor i left join projectInvest pi on i.i_id=pi.i_id ");
		str.append(" ORDER BY i_ctime asc limit ");
		str.append((page-1) * count);
		str.append(",");
		str.append(count);
		List<Object> lists = new ArrayList<>();
		List<Object> list = null;
		Investor inve = null;
		Projectinvest pi = null;
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(str.toString());
			rs = ps.executeQuery();
			while(rs.next()) {
				list = new ArrayList<>();
				inve = new Investor( 
						rs.getInt("i_id"),
						rs.getString("i_name"),
						rs.getString("i_logo"),
						rs.getString("i_loname"),
						null,
						rs.getString("i_explain"),
						rs.getDate("i_ctime"),
						rs.getString("i_tel"),
						rs.getDouble("i_amount"));
				pi = new Projectinvest(
						rs.getInt("pi_id"),
						rs.getInt("i_id"),
						rs.getInt("p_id"),
						rs.getDouble("pi_amount"),
						rs.getDate("pi_time"),
						rs.getString("pi_explain"));
				list.add(inve);
				list.add(pi);
				lists.add(list);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e.getMessage());
		} finally {
			Conn.close(rs, ps, conn);
		}
		return lists;
	}

	@Override
	public int countInve(int type) {
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuilder str = new StringBuilder("select count(i_id) as count from investor ");
		int count = 1;
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(str.toString());
			rs = ps.executeQuery();
			while(rs.next()) {
				count = rs.getInt("count");
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e.getMessage());
		} finally {
			Conn.close(rs, ps, conn);
		}
		return count;
	}
	
	@Override
	public List<Object> listTeam( int page, int count) {
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuilder str = new StringBuilder("select * from team t left join project p on t.te_id=p.te_id left join projecType pt on p.pt_id=pt.pt_id left join projectInvest pi on p.p_id=pi.p_id group by t.te_id ");
		str.append(" ORDER BY t.te_ctime desc limit ");
		str.append((page-1) * count);
		str.append(",");
		str.append(count);
		List<Object> lists = new ArrayList<>();
		List<Object> list = null;
		Team team = null;
		Project p = null;
		ProjecType pt = null;
		Projectinvest pi = null;
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(str.toString());
			rs = ps.executeQuery();
			while(rs.next()) {
				list = new ArrayList<>();
				team = new Team(
						rs.getString("te_name"),
						rs.getString("te_logo"),
						rs.getString("te_loname"),
						null,
						rs.getDate("te_ctime"),
						rs.getString("te_explain"),
						rs.getInt("te_id"),
						null);
				p = new Project(
						rs.getInt("p_id"),
						rs.getString("p_name"),
						rs.getString("p_logo"),
						rs.getDate("p_ctime"),
						rs.getDate("p_ltime"),
						rs.getInt("p_status"),
						rs.getInt("p_progress"),
						rs.getInt("p_view"),
						rs.getString("p_content"),
						rs.getString("p_explain"),
						rs.getInt("te_id"),
						rs.getInt("pt_id"),
						rs.getString("p_remarks"),
						rs.getString("p_filename"),
						rs.getString("p_filepath"));
				pt = new ProjecType(
						rs.getInt("pt_id"),
						rs.getString("pt_name"),
						rs.getString("pt_explain"));
				pi = new Projectinvest(
						rs.getInt("pi_id"),
						rs.getInt("i_id"),
						rs.getInt("p_id"),
						rs.getDouble("pi_amount"),
						rs.getDate("pi_time"),
						rs.getString("pi_explain"));
				list.add(team);
				list.add(p);
				list.add(pt);
				list.add(pi);
				lists.add(list);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e.getMessage());
		} finally {
			Conn.close(rs, ps, conn);
		}
		return lists;
	}

	@Override
	public int countTeam() {
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuilder str = new StringBuilder("select count(te_id) as count from team ");
		int count = 1;
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(str.toString());
			rs = ps.executeQuery();
			while(rs.next()) {
				count = rs.getInt("count");
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e.getMessage());
		} finally {
			Conn.close(rs, ps, conn);
		}
		return count;
	}

	
	@Override
	public List<Object> listPros( int type, int page, int count) {
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuilder str = new StringBuilder("select * from project p left join projecType pt on pt.pt_id=p.pt_id left join team t on p.te_id=t.te_id left join projectInvest pi on pi.p_id=p.p_id left join investor i on i.i_id=pi.i_id");
//		if( type != 255) {
			str.append(" where p.p_status=1");
//			str.append(type);
//		}
		str.append(" ORDER BY p.p_progress desc limit ");
		str.append((page-1) * count);
		str.append(",");
		str.append(count);
		List<Object> lists = new ArrayList<>();
		List<Object> list = null;
		Team team = null;
		Project p = null;
		ProjecType pt = null;
		Projectinvest pi = null;
		Investor inve = null;
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(str.toString());
			rs = ps.executeQuery();
			while(rs.next()) {
				list = new ArrayList<>();
				p = new Project(
						rs.getInt("p_id"),
						rs.getString("p_name"),
						rs.getString("p_logo"),
						rs.getDate("p_ctime"),
						rs.getDate("p_ltime"),
						rs.getInt("p_status"),
						rs.getInt("p_progress"),
						rs.getInt("p_view"),
						rs.getString("p_content"),
						rs.getString("p_explain"),
						rs.getInt("te_id"),
						rs.getInt("pt_id"),
						rs.getString("p_remarks"),
						rs.getString("p_filename"),
						rs.getString("p_filepath"));
				pt = new ProjecType(
						rs.getInt("pt_id"),
						rs.getString("pt_name"),
						rs.getString("pt_explain"));
				team = new Team(
						rs.getString("te_name"),
						rs.getString("te_logo"),
						rs.getString("te_loname"),
						null,
						rs.getDate("te_ctime"),
						rs.getString("te_explain"),
						rs.getInt("te_id"),
						null);
				pi = new Projectinvest(
						rs.getInt("pi_id"),
						rs.getInt("i_id"),
						rs.getInt("p_id"),
						rs.getDouble("pi_amount"),
						rs.getDate("pi_time"),
						rs.getString("pi_explain"));
				inve = new Investor(
						rs.getInt("i_id"),
						rs.getString("i_name"),
						rs.getString("i_logo"),
						rs.getString("i_loname"),
						null,
						rs.getString("i_explain"),
						rs.getDate("i_ctime"),
						rs.getString("i_tel"),
						rs.getDouble("i_amount"));
				list.add(p);
				list.add(pt);
				list.add(team);
				list.add(pi);
				list.add(inve);
				lists.add(list);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e.getMessage());
		} finally {
			Conn.close(rs, ps, conn);
		}
		return lists;
	}

	@Override
	public int countPros( int type) {
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuilder str = new StringBuilder("select count(p_id) as count from project where p_status=1");
		int count = 1;
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(str.toString());
			rs = ps.executeQuery();
			while(rs.next()) {
				count = rs.getInt("count");
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e.getMessage());
		} finally {
			Conn.close(rs, ps, conn);
		}
		return count;
	}


	@Override
	public List<Object> listNews( int type, int page, int count) {
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuilder str = new StringBuilder("select * from notice n left join admin a on n.a_id=a.a_id left join noticeType nt on nt.nt_id=n.nt_id ");
		if( type != 255) {
			str.append(" where n.nt_id=");
			str.append(type);
		}
		str.append(" ORDER BY n.n_ctime desc limit ");
		str.append((page-1) * count);
		str.append(",");
		str.append(count);
		List<Object> lists = new ArrayList<>();
		List<Object> list = null;
		Notice news = null;
		Admin admin = null;
		Noticetype nt = null;
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(str.toString());
			rs = ps.executeQuery();
			while(rs.next()) {
				list = new ArrayList<>();
				news = new Notice(
						rs.getInt("n_id"),
						rs.getString("n_title"),
						null,
						rs.getInt("n_view"),
						rs.getDate("n_ctime"),
						rs.getInt("nt_id"),
						rs.getInt("a_id"),
						rs.getString("n_filename"),
						rs.getString("n_filepath"),
						rs.getString("n_filexplain"));
				nt = new Noticetype(
						rs.getInt("nt_id"),
						rs.getString("nt_name"),
						rs.getString("nt_explain"));
				admin = new Admin();
				admin.setA_id(rs.getInt("a_id"));
				admin.setA_name(rs.getString("a_name"));
				list.add(news);
				list.add(nt);
				list.add(admin);
				lists.add(list);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e.getMessage());
		} finally {
			Conn.close(rs, ps, conn);
		}
		return lists;
	}

	@Override
	public int countNews( int type) {
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuilder str = new StringBuilder("select count(n_id) as count from notice ");
		if(type != 255) {
			str.append(" where nt_id=");
			str.append(type);
		}
		int count = 1;
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(str.toString());
			rs = ps.executeQuery();
			while(rs.next()) {
				count = rs.getInt("count");
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e.getMessage());
		} finally {
			Conn.close(rs, ps, conn);
		}
		return count;
	}

	@Override
	public int countCdyy( String loname) {
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuilder str = new StringBuilder("select count(f_id) as count from field where f_user=?;");
		int count = 1;
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(str.toString());
			ps.setString(1, loname);
			rs = ps.executeQuery();
			while(rs.next()) {
				count = rs.getInt("count");
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e.getMessage());
		} finally {
			Conn.close(rs, ps, conn);
		}
		return count;
	}
	public List<Noticetype> noticeTypes() {
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuilder str = new StringBuilder("SELECT * from noticeType;");
		List<Noticetype> list = new ArrayList<>();
		Noticetype nt = null;
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(str.toString());
			rs = ps.executeQuery();
			while(rs.next()) {
				nt = new Noticetype(
						rs.getInt("nt_id"),
						rs.getString("nt_name"),
						rs.getString("nt_explain"));
				list.add(nt);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e.getMessage());
		} finally {
			Conn.close(rs, ps, conn);
		}
		return list;
	}
	
	//////////////////ajax///////////////////////
	
	@Override
	public Investor invenfo(int id) {
		String sql = "select * from investor where i_id=?";
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		Investor inve = null;
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(sql);
			ps.setInt(1, id);
			rs = ps.executeQuery();
			while(rs.next()) {
				inve = new Investor(
						rs.getInt("i_id"),
						rs.getString("i_name"),
						rs.getString("i_logo"),
						null,
						null,
						rs.getString("i_explain"),
						null,
						rs.getString("i_tel"),
						rs.getDouble("i_amount"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e.getMessage());
		} finally {
			Conn.close(rs, ps, conn);
		}
		return inve;
	}

	@Override
	public List<Object> invePro(int id) {
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuilder str = new StringBuilder("select * from projectInvest pi left join investor i on i.i_id=pi.i_id left join project p on p.p_id=pi.p_id left join projecType pt on pt.pt_id=p.pt_id where i.i_id=? and p.p_status=1;");
		List<Object> lists = new ArrayList<>();
		List<Object> list  = null;
		Project pro = null;
		Projectinvest pi = null;
		ProjecType pt  = null;
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(str.toString());
			ps.setInt(1, id);
			rs = ps.executeQuery();
			while(rs.next()) {
				list = new ArrayList<>();
				pro = new Project(
						rs.getInt("p_id"),
						rs.getString("p_name"),
						rs.getString("p_logo"),
						rs.getDate("p_ctime"),
						rs.getDate("p_ltime"),
						rs.getInt("p_status"),
						rs.getInt("p_progress"),
						rs.getInt("p_view"),
						rs.getString("p_content"),
						rs.getString("p_explain"),
						rs.getInt("te_id"),
						rs.getInt("pt_id"),
						rs.getString("p_remarks"),
						rs.getString("p_filename"),
						rs.getString("p_filepath"));

				pi = new Projectinvest(
						rs.getInt("pi_id"),
						rs.getInt("i_id"),
						rs.getInt("p_id"),
						rs.getDouble("pi_amount"),
						rs.getDate("pi_time"),
						rs.getString("pi_explain"));

				pt =  new ProjecType(
						rs.getInt("pt_id"),
						rs.getString("pt_name"),
						rs.getString("pt_explain"));
				list.add(pro);
				list.add(pt);
				list.add(pi);
				lists.add(list);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e.getMessage());
		} finally {
			Conn.close(rs, ps, conn);
		}
		return lists;
	}
	
	@Override
	public List<Object> proInfo(int id) {
		String sql = "select * from project p left join projectInvest pi on p.p_id=pi.p_id left join investor i on i.i_id=pi.i_id left join team te on te.te_id=p.te_id left join projecType pt on pt.pt_id=p.pt_id where p.p_id=? and p.p_status=1;";
		List<Object> list = new ArrayList<>();//装下面五个的容器
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		Project pro = null;
		Projectinvest pi = null;
		Investor in = null;
		Team te = null;
		ProjecType pt = null;
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(sql);
			ps.setInt(1, id);
			rs = ps.executeQuery();
			while (rs.next()) {
				pro = new Project();//项目的容器
				pi = new Projectinvest();//项目与投资人关系的容器
				in = new Investor();//投资人的容器
				te = new Team();//团队的容器

				pro.setP_content(rs.getString("P_content"));
				pro.setP_ctime(rs.getDate("P_ctime"));
				pro.setP_explain(rs.getString("P_explain"));
				pro.setP_id(rs.getInt("P_id"));
				pro.setTe_id(rs.getInt("p_view"));
				pro.setTe_id(rs.getInt("p_view"));
				pro.setP_logo(rs.getString("P_logo"));
				pro.setP_ltime(rs.getDate("P_ltime"));
				pro.setP_name(rs.getString("P_name"));
				pro.setP_progress(rs.getInt("P_progress"));
				pro.setP_status(rs.getInt("p_status"));
				pro.setTe_id(rs.getInt("Te_id"));
				pro.setTe_id(rs.getInt("p_view"));

				pi.setI_id(rs.getInt("I_id"));
				pi.setP_id(rs.getInt("P_id"));
				pi.setPi_amount(rs.getDouble("Pi_amount"));
				pi.setPi_explain(rs.getString("Pi_explain"));
				pi.setPi_id(rs.getInt("Pi_id"));
				pi.setPi_time(rs.getDate("Pi_time"));

				in.setI_explain(rs.getString("I_explain"));
				in.setI_id(rs.getInt("I_id"));
				in.setI_logo(rs.getString("I_logo"));
				in.setI_name(rs.getString("I_name"));

				te.setTe_explain(rs.getString("Te_explain"));
				te.setTe_id(rs.getInt("Te_id"));
				te.setTe_logo(rs.getString("Te_logo"));

				pt =  new ProjecType(
						rs.getInt("pt_id"),
						rs.getString("pt_name"),
						rs.getString("pt_explain"));

				list.add(pro);
				list.add(pi);
				list.add(in);
				list.add(te);
				list.add(pt);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			Conn.close(rs, null, null);
		}
		return list;
	}
	
	@Override
	public Team teamInfo(int id) {
		String sql = "select * from team where te_id=?";
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		Team team = null;
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(sql);
			ps.setInt(1, id);
			rs = ps.executeQuery();
			while(rs.next()) {
				team = new Team(
						rs.getString("te_name"),
						rs.getString("te_logo"),
						rs.getString("te_loname"),
						null,
						null,
						rs.getString("te_explain"),
						rs.getInt("te_id"),
						null);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e.getMessage());
		} finally {
			Conn.close(rs, ps, conn);
		}
		return team;
	}

	@Override
	public List<Object> memberInfo(int tid) {
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		StringBuilder str = new StringBuilder("select * from member m left join teamUnite tu on m.m_id=tu.m_id left join team t on t.te_id=tu.te_id where t.te_id=? order by tu.tun_type desc");
		List<Object> lists = new ArrayList<>();
		Member m = null;
		Teamunite tu = new Teamunite();
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(str.toString());
			ps.setInt(1, tid);
			rs = ps.executeQuery();
			while(rs.next()) {
				List<Object> list = new ArrayList<>();
				m = new Member(
						rs.getInt("m_id"),
						rs.getString("m_name"),
						rs.getString("m_sex"),
						rs.getString("m_logo"),
						null,
						rs.getString("m_tel"),
						null,
						rs.getString("m_xl"),
						null,
						null,
						null,
						null,
						rs.getString("m_explain"),
						null);
				tu.setTun_type(rs.getString("tun_type"));

				list.add(m);
				list.add(tu);
				lists.add(list);
			}

		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e.getMessage());
		} finally {
			Conn.close(rs, ps, conn);
		}
		return lists;
	}
	
	@Override
	public List<Object> tutorInfo(int id) {
		String sql = "select * from tutor t left join guiDirection gd on gd.gd_id=t.gd_id where t.tu_id=?";
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		List<Object> lists = new ArrayList<>();
		List<Object> list = null;
		Tutor tutor = null;
		GuiDirection gd = null;
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(sql);
			ps.setInt(1, id);
			rs = ps.executeQuery();
			while(rs.next()) {
				list = new ArrayList<>();
				tutor = new Tutor(
						rs.getInt("tu_id"),
						rs.getString("tu_name"),
						rs.getString("tu_logo"),
						rs.getString("tu_loname"),
						null,
						rs.getString("tu_tel"),
						rs.getString("tu_explain"),
						null,
						rs.getInt("gd_id"));
				tutor.setTu_type(rs.getInt("tu_type"));
				
				gd = new GuiDirection();
				gd.setGd_name(rs.getString("gd_name"));
				
				list.add(tutor);
				list.add(gd);
				lists.add(list);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e.getMessage());
		} finally {
			Conn.close(rs, ps, conn);
		}
		return lists;
	}

	@Override
	public List<Object> tutorTeam(int id) {
	Connection conn = null;
	PreparedStatement ps = null;
	ResultSet rs = null;
	StringBuilder str = new StringBuilder("select * from team t left join teamTutor tt on t.te_id=tt.te_id left join tutor tu on tu.tu_id=tt.tu_id where tt_teamcheck=2 and tt_tutorcheck=2 and tu.tu_id=?;");
	List<Object> lists = new ArrayList<>();
	Member m = null;
	Teamunite tu = new Teamunite();
	try {
		conn = Conn.getConnect();
		ps = conn.prepareStatement(str.toString());
		ps.setInt(1, id);
		rs = ps.executeQuery();
		while(rs.next()) {
			List<Object> list = new ArrayList<>();
			m = new Member(
					rs.getInt("m_id"),
					rs.getString("m_name"),
					rs.getString("m_sex"),
					rs.getString("m_logo"),
					null,
					rs.getString("m_tel"),
					null,
					rs.getString("m_xl"),
					null,
					null,
					null,
					null,
					rs.getString("m_explain"),
					null);
			tu.setTun_type(rs.getString("tun_type"));

			list.add(m);
			list.add(tu);
			lists.add(list);
		}

	} catch (SQLException e) {
		e.printStackTrace();
		throw new RuntimeException(e.getMessage());
	} finally {
		Conn.close(rs, ps, conn);
	}
	return lists;
}
	
	@Override
	public List<Object> newsInfo(int id) {
		StringBuilder str = new StringBuilder("select * from notice n left join admin a on a.a_id=n.a_id left join noticeType nt on nt.nt_id=n.nt_id where n.n_id=?");
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		List<Object> lists = new ArrayList<>();
		Notice notice = null;
		Admin admin = null;
		Noticetype noticetype = null;
		try {
			conn = Conn.getConnect();
			ps = conn.prepareStatement(str.toString());
			ps.setInt(1, id);
			rs = ps.executeQuery();
			while(rs.next()) {
				notice = new Notice(
						rs.getInt("n_id"),
						rs.getString("n_title"),
						rs.getString("n_content"),
						rs.getInt("n_view"),
						rs.getDate("n_ctime"),
						rs.getInt("nt_id"),
						rs.getInt("a_id"),
						rs.getString("n_filename"),
						rs.getString("n_filepath"),
						rs.getString("n_filexplain"));
				admin = new Admin(
						rs.getInt("a_id"),
						rs.getString("a_name"),
						null,
						null,
						null,
						null);
				noticetype = new Noticetype(
						rs.getInt("nt_id"),
						rs.getString("nt_name"),
						rs.getString("nt_explain"));
				lists.add(notice);
				lists.add(admin);
				lists.add(noticetype);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e.getMessage());
		} finally {
			Conn.close(rs, ps, conn);
		}
		return lists;
	}

	//////////////////ajax////////////////////////
	
	
	@Override
	public boolean addTeam(Team team) {
		Connection conn = null;
		PreparedStatement ps = null;
		int flag = 0;
		String sql = "insert into team( te_id, te_name, te_loname, te_passw, te_ctime) values(0, ?, ?, ?, sysdate());";
		try {
			conn = Conn.getConnect();
			ps =  conn.prepareStatement(sql);
			ps.setString(1, team.getTe_name());
			ps.setString(2, team.getTe_loname());
			ps.setString(3, team.getTe_passw());
			flag = ps.executeUpdate();
		} catch (Exception e1) {
			e1.printStackTrace();
			throw new RuntimeException(e1.getMessage());
		} finally {
			Conn.close( null, ps, conn);
		}
		return flag ==0?false:true;
	}
	
	@Override
	public boolean addTeac(Tutor teac) {
		Connection conn = null;
		PreparedStatement ps = null;
		int flag = 0;
		String sql = "insert into tutor(tu_id, tu_name, tu_loname, tu_passw, tu_ctime) values( 0, ?, ?, ?, sysdate());";
		try {
			conn = Conn.getConnect();
			ps =  conn.prepareStatement(sql);
			ps.setString(1, teac.getTu_name());
			ps.setString(2, teac.getTu_loname());
			ps.setString(3, teac.getTu_passw());
			flag = ps.executeUpdate();
		} catch (Exception e1) {
			e1.printStackTrace();
			throw new RuntimeException(e1.getMessage());
		} finally {
			Conn.close( null, ps, conn);
		}
		return flag == 0?false:true;
	}

	@Override
	public boolean addProZan(int pid) {
		Connection conn = null;
		PreparedStatement ps = null;
		int flag = 0;
		String sql = "update project set p_zan=p_zan+1 where p_id=?;";
		try {
			conn = Conn.getConnect();
			ps =  conn.prepareStatement(sql);
			ps.setInt(1, pid);
			flag = ps.executeUpdate();
		} catch (Exception e1) {
			e1.printStackTrace();
			throw new RuntimeException(e1.getMessage());
		} finally {
			Conn.close( null, ps, conn);
		}
		return flag == 0?false:true;
	}
}
